package com.lsongh.springBoot.controller;

import com.lsongh.springBoot.entity.Result;
import com.lsongh.springBoot.entity.User;
//import com.lsongh.springBoot.filter.LoginFilter;
import com.lsongh.springBoot.service.UserService;
import com.lsongh.springBoot.utils.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;

@RestController
public class LoginController {

    @Autowired
    UserService userService;
    /**
     * 登录
     * @param name
     * @param password
     * @return
     */
    @RequestMapping(value = "/login", method = RequestMethod.POST)
    public Result Login(@RequestParam("name") String name,
                        @RequestParam("password") String password,
                        HttpSession session) {
        User user = userService.findByName(name);
        if (user.getPassword().equals(password)) {
           // session.setAttribute(LoginFilter.SESSION_KEY, name);
            return ResultUtil.success(user);
        } else {
            return ResultUtil.success("密码不正确");
        }

       // return  ResultUtil.success("登录成功");
    }

//    @RequestMapping("/login")
//    public String login() {
//        return "login";
//    }
//
    @RequestMapping("/")
    public String hello(){
        return "index";
    }
//
//    @RequestMapping(value = "/index", method = RequestMethod.GET)
//    public String index() {
//        return "index";
//    }
//
//    @RequestMapping(value = "/logout", method = RequestMethod.GET)
//    public String logout(HttpSession session) {
//        //session.removeAttribute(LoginFilter.SESSION_KEY);
//        return "login";
//    }

}
